import { Component, OnInit, DoCheck, Input, OnChanges, SimpleChange, ViewChild, ElementRef } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { Http, Response, Headers, RequestOptions, URLSearchParams } from '@angular/http';
import LCalendar from "../../assets/js/lCalendar (2).js";
import { ConmonService } from "../../service/common.service";
import * as $ from 'jquery';
export class ProjectScreening {
  // id: number;
  // 员工姓名
  PplName: string;
  // 员工编号
  employId: string;
  // 报工日期
  WorkDate: string;
  //  报工提交日期
  SubmitDate: string;
  WorkType: string;
  // 项目名称
  ProName: string;
  //  项目编号
  ProId: string;
  // 工作内容
  WorkContent: string;
  // 消耗工时
  ConsumeTime: any;
  // 归属部门
  AtbutDept:any;
  //获取页数
  AccessPages:string;
}
@Component({
  selector: 'app-project-screening',
  templateUrl: './project-screening.component.html',
  styleUrls: ['./project-screening.component.scss']
})
export class ProjectScreeningComponent implements OnInit {
  @Input() ProjectScreening: ProjectScreening = {
    // id: 1,
    PplName: '',
    employId: '',
    WorkDate: '',
    SubmitDate: '',
    ProName: '',
    WorkType: '',
    ProId: '',
    WorkContent: '',
    ConsumeTime: '',
    AtbutDept: '',
    AccessPages: '1'
  };
  private iswork: boolean = false;
  private isAddWork: boolean = false;
  private isleave: boolean = false;
  private isFishesd: boolean = false;
  private dataObj:any;
  private dataList:any;
  private projectNameFlag: boolean = false;
  private projectIdFlag: boolean = false;
  private proType: string = '';
  choiceWorkType($event) {
    var val = $event.target.value;
    if (val === '工作') {
      this.iswork = true;
      this.isleave = false;
      this.isAddWork = false;
      this.ProjectScreening.WorkType = '0';

    } else if (val === '加班') {
      // console.log(this);
      this.isAddWork = true;
      this.isleave = false;
      this.iswork = false;
      this.ProjectScreening.WorkType = '1';
    } else if (val === '请假') {
      //   console.log(this);
      this.isleave = true;
      this.isAddWork = false;
      this.iswork = false;
      this.ProjectScreening.WorkType = '2';
    }
    // this.workadd.workType[this.workadd.workType.length-1];
  }
  // 发送请求，从后台传输数据
  results: string[];
  ngAfterViewInit() {
    console.log(document.getElementById('employeeDate'))
    if (document.getElementById('employeeDate')) {
      // 我的报工添加的选择报工日期日历插件调用
      var calendar = new LCalendar();
      calendar.init({
        'trigger': '#employeeDate', //标签id
        'type': 'date', //date 调出日期选择 datetime 调出日期时间选择 time 调出时间选择 ym 调出年月选择,
        'minDate': '1900-1-1', //最小日期
        'maxDate': new Date().getFullYear() + 10 + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate() //最大日期
      });
    }
    // 我的报工添加的选择报工日期日历插件调用
    var DateSubmit = new LCalendar();
    console.log(document.getElementById('DateSubmit'))
    if (document.getElementById('DateSubmit')) {
      DateSubmit.init({
        'trigger': '#DateSubmit', //标签id
        'type': 'date', //date 调出日期选择 datetime 调出日期时间选择 time 调出时间选择 ym 调出年月选择,
        'minDate': '1900-1-1', //最小日期
        'maxDate': new Date().getFullYear() + 10 + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate() //最大日期
      });
    }
  };
  @ViewChild('nameSearchList')
  // projectNameSearch: ElementRef;
  nameSearchList: ElementRef;
  //调项目名称的搜索，改变搜索结果的样式
  keyChangeColor(value: string,obj) {
    this.projectNameFlag = true;
    console.log(obj.target.nextElementSibling);
    this.dataObj = {
      SearchProType: '1',
      ProName: value,
      ProId: '',
      ProMana: ''
    };
   this.dataList = this.service.withBodyData(this.dataObj,'joinWorkProListInfo')
    console.log(this.dataList);
    // let array = value.split(""); //分割
    // let  dsa=this.projectNameSearch.nativeElement;//获取全部商品
    setTimeout(function(){
      let dsa = $(obj.target.nextElementSibling).find('li');
      for (let t = 0; t < dsa.length; t++) {
        let val = dsa.eq(t).text();
        console.log(val);
        let x = val.replace(value,"<span class='col_Color' style='color:#54a3ff;'>"+value+"</span>");
        $(obj.target.nextElementSibling).find('li').eq(t).html(x);
      };
    },0)
  };
  //为项目名称搜索出来的结果赋值
  addProjectName (obj) {
    console.log(obj);
    this.ProjectScreening.ProName = obj.ProName;
    this.ProjectScreening.ProId = obj.ProId;
    this.proType = obj.DailyWorkType;
    this.projectNameFlag = false;
    // this.dataList = '';
  };
  //项目名称失去焦点
  pronameBlur () {
    let proNameValue = $("#projectName").val();
    // let proIdValue = $("#projectNumber").val();
    this.dataObj = {
      SearchProType: '1',
      ProName: proNameValue,
      ProId: '',
      ProMana: ''
    };
    let resData = this.service.withBodyData(this.dataObj, 'joinWorkProListInfo');
    console.log(resData);
    if (resData.body.ProInfo.length === 1) {
      this.ProjectScreening.ProId = resData.body.ProInfo[0].ProId;
      this.proType = resData.body.ProInfo[0].DailyWorkType;
    }
    let _this = this;
    setTimeout(function(){
      _this.projectNameFlag = false;
    },301)
    // this.dataList = '';
  };
  //项目编号搜索
  projectIdSearch (value: string,obj) {
    this.projectIdFlag = true;
    console.log(value);
    this.dataObj = {
      SearchProType: '1',
      ProName: '',
      ProId: value,
      ProMana: ''
    };
   this.dataList = this.service.withBodyData(this.dataObj,'joinWorkProListInfo')
    console.log(this.dataList);
    // let array = value.split(""); //分割
    // let  dsa=this.projectNameSearch.nativeElement;//获取全部商品
    setTimeout(function(){
      let dsa = $(obj.target.nextElementSibling).find('li');
      for (let t = 0; t < dsa.length; t++) {
        let val = dsa.eq(t).text();
        console.log(val);
        let x = val.replace(value,"<span class='col_Color' style='color:#54a3ff;'>"+value+"</span>");
        $(obj.target.nextElementSibling).find('li').eq(t).html(x);
      };
    },0)
  };
  //项目编号失去焦点
  projectNumberBlur () {
    // this.dataList = '';
    // let proNameValue = $("#projectName").val();
    // let proIdValue = $("#projectNumber").val();
    let proIdValue = this.ProjectScreening.ProId;
    console.log(proIdValue);
    this.dataObj = {
      SearchProType: '1',
      ProName: '',
      ProId: proIdValue,
      ProMana: ''
    };
    let resData = this.service.withBodyData(this.dataObj, 'joinWorkProListInfo');
    console.log(resData);
    if (resData.body.ProInfo.length === 1) {
      this.ProjectScreening.ProName = resData.body.ProInfo[0].ProName;
      this.proType = resData.body.ProInfo[0].DailyWorkType;
    }
    let _this = this;
    setTimeout(function(){
      _this.projectIdFlag = false;
    },301)
  };
  //为项目编号搜索出来的结果添加赋值
  addProjectId (obj) {
    this.ProjectScreening.ProName = obj.ProName;
    this.ProjectScreening.ProId = obj.ProId;
    this.proType = obj.DailyWorkType;
    // this.dataList = '';
    this.projectIdFlag = false;
  };
  ngOnInit() {
    // 初始化获取数据信息
  }
  constructor( private router: Router,private activatedRoute: ActivatedRoute,private http: HttpClient,private service:ConmonService) {}
  // 报工添加点击确定判断是否跳转
  sureShow(): void {
    //  这里要传当前页面的数据给后台
    console.log(this.ProjectScreening);
    this.service.saveProjectScreeningData(this.ProjectScreening,'FiltrateProjectWork');
    this.router.navigate(['/ProjectTotal',false]);
  }
  //   重置方法
  resetBtn() {
    console.log(this.ProjectScreening)
    for (let item in this.ProjectScreening) {
      this.ProjectScreening[item] = ''
    }
  };
}
